package dev.ece.suit.bloom;

import java.io.InputStream;

import org.lwjgl.opengl.GL20;

import dev.ece.core.shader.Shader;
import dev.ece.core.texture.Texture;
/**
 * 高斯模糊
 * @author 潜行的虚影
 *
 */
public class GaussianBlurShader extends Shader {

	private int textureHandler;
	
	private int statusHandler;
	
	public GaussianBlurShader(InputStream vertexShaderInputStream,
			InputStream pixelShaderInputStream) {
		super(vertexShaderInputStream, pixelShaderInputStream);
	}
	
	@Override
	protected void onInitializeHandler(int program) {
		textureHandler = glGetUniformLocation("texture");
		statusHandler = glGetUniformLocation("status");
	}

	@Override
	protected void onBindAttribLocations(int program) {
		bindAttribLocation("vao_Vertex");
		bindAttribLocation("vao_TexCoord");
	}
	
	/**
	 * 
	 * @param status 2、提取亮度，0、水平模糊，1、垂直模糊
	 */
	public void glStatus(int status) {
		GL20.glUniform1i(statusHandler, status);
	}
	
	public void glTexture(Texture texture) {
		GL20.glUniform1i(textureHandler, texture.bind(0));
	}
	
	public static GaussianBlurShader createGaussianBlurShader() {
		GaussianBlurShader shader = new GaussianBlurShader(
				GaussianBlurShader.class.getClassLoader().getResourceAsStream("shaders/gaussianblur.vert"),
				GaussianBlurShader.class.getClassLoader().getResourceAsStream("shaders/gaussianblur.frag"));
		return shader;
	}

	@Override
	public void clearup() {
		GL20.glDeleteShader(this.textureHandler);
		super.clearup();
	}
	
}
